<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    const array = [1, 2, 3, 4, 5, 6, 7, 8, 9]

    // function shuffle(arr) {
    //   for (let i = 0, len = arr.length; i < len; i++) {
    //     // 产生随机下标
    //     const rand = Math.floor(Math.random() * len)
    //     // 交互当前元素与随机下标处的元素位置
    //     const temp = arr[i]
    //     arr[i] = arr[rand]
    //     arr[rand] = temp
    //   }
    // }

    function shuffle(arr) {
      return arr.sort(() => Math.random() - 0.5)
    }

    console.log('前：', array)
    shuffle(array)
    console.log('后：', array)
  </script>

  <script>
    const str = 'abcdefg'

    console.log(str.__proto__)

    String.prototype.shuffle = function() {
      return this.split('').sort(() => Math.random() - 0.5).join('')
    }

    console.log(str.shuffle())   
    console.log(str.shuffle())   
    console.log(str.shuffle())   
    console.log(str.shuffle())   
    console.log(str.shuffle())   

    // console.log(str.split('').join('-'))
  </script>
</body>
</html>